/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/

#ifndef _POSITION_FILE_READER_HPP
#define _POSITION_FILE_READER_HPP

#include "owndebug.h"
#include <string>
#include "PositionData.hpp"
#include "PositionFileWriter.hpp"
#include "gimutils.h"
#include "ownutils.h"
#include <map>
#include <list>
#include <string>
#include <stdio.h>
typedef std::map<gim::time,MaCI::Position::CPositionData *> TPositionDataMap;

class CPositionFileReader{
public:
  /**
   * Constructor
   */
  CPositionFileReader();

  /**
   * Destructor
   */
  ~CPositionFileReader();

  /**
   * Opens file with wanted filename
   */
  bool ReadFile(std::string aFileName);

  
  bool GetServiceInformation(std::string &aMaCIGroup,
                             std::string &aInstanceName);

  bool GetTimes(std::list<gim::time> &aTimes);
  bool GetTimeLimits(gim::time &aBegin,gim::time &aEnd);

  bool GetAllData(TPositionDataMap &aData);
  

  bool GetPositionData(MaCI::Position::CPositionData &aData,
                       gim::time aTime);

  bool GetPositionData(TPositionLogLine &aData,
                       gim::time aTime);
 
  bool GetPositionData(MaCI::Position::TPose2D &aData,
                       gim::time aTime);

  bool GetPositionData(MaCI::Position::TPose3D &aData,
                       gim::time aTime);

  bool GetPositionData(MaCI::Position::TPose2D &aPose,
                       MaCI::Position::TSpeed2D &aSpeed,
                       MaCI::Position::TVariance2D &aVariance,
                       MaCI::Position::TProbability &aProbability,
                       gim::time aTime);

  
											 
  bool getClosestTo(MaCI::Position::CPositionData &aData, gim::time aTime);
  
private:
  bool iFileReaded;  
  TPositionDataMap iData;
  std::list<gim::time> iTimes;
  gim::time iBegin;
  gim::time iEnd;
  std::string iMaCIGroup;
  std::string iInstanceName;
  bool iContainsTimestamp;
  bool iContainsPosition;
  bool iContainsVariance;
  bool iContainsProbability;
  bool iContainsSpeed;


  bool ReadData(FILE *iFile);
  bool ReadDataV_2_0(FILE *file);
  CPositionFileReader(const CPositionFileReader&)
    :iFileReaded(false),
     iData(),
     iTimes(),
     iBegin(),
     iEnd(),
     iMaCIGroup(""),
     iInstanceName(""),
     iContainsTimestamp(false),
     iContainsPosition(false),
     iContainsVariance(false),
     iContainsProbability(false),
     iContainsSpeed(false){}

  CPositionFileReader &operator=(const  CPositionFileReader&){return *this;}

};
#endif ///< _POSITION_FILE_READER_HPP
